import { observable,computed,action} from "mobx";
// @observable   mobx要使用修饰器  需要先安装bael包并设置 注意项目开发依赖
// npm install --save-dev @babel/plugin-proposal-decorators mobx
// @observable  这个装饰器代表可观察的状态   和vue的store里面的state同理
import {getSessionStorage,setSessionStorage} from '../util/storage'
class HomeStore {
    // @observable isLogin = getSessionStorage('isLogin') || false;
    // @observable permissions = getSessionStorage('permissions') || "";
    @observable user = getSessionStorage('user') || {isLogin:false,permissions:""};
    @observable myname = '佳能瓜皮';
    // @observable stu = [
    //     {id:1,name:'张三',age:15},
    //     {id:2,name:'李四',age:17},
    //     {id:3,name:'王五',age:22},
    // ];
    // @computed get getstuAge(){
    //     return this.stu.map((item)=>{
    //         item.age = item.age+10
    //         return item
    //     })
    // }
    @action
    loginServer = ()=>{
        return new Promise((resolve, reject)=>{
            // 这里请求ajax
            resolve(true)
        }).then(res=>{
            let obj =  {
                isLogin:res,
                permissions:'user1'
            }
            this.user = {...obj}
            setSessionStorage('user',obj)
            return '登录成功'
        })
    }
    @action
    loginOut = ()=>{
        console.log(123)
        this.user = {isLogin:false,permissions:""};
        setSessionStorage('user',"")

    }
    // loginOut(){
    //     this.user = {
    //         isLogin:false,
    //         permissions:""
    //     }
    // }
}
export default HomeStore;